﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class webloadtest : System.Web.UI.Page
{
    private DataBaseAccess GetDataBaseAccess()
    {
        ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"];
        return new DataBaseAccess(setting.ConnectionString);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextBox1.Text = DateTime.Now.ToString();
            TextBox6.Text = "2";
            TextBox2.Text = TextBox7.Text = "webloadtest";
            TextBox3.Text = "webloadtest1";
            TextBox4.Text = "@any";
            TextBox5.Text = @"/draw_strokes 0:36:0:-65536:1$8200:5061&8793:4918&9434:4801&10051:4710&10667:4684&11127:4762&11369:4879&11442:4905&11345:4658&10861:4176&9785:3539&9010:3201&8382:3058&7837:3031&7426:3240&7257:3656&7341:4384&7753:5608&8067:6233&8116:6532&7934:6935&7583:7416";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataBaseAccess dba = GetDataBaseAccess();
        DateTime dt = DateTime.Now;//.Parse(TextBox1.Text);
        dba.WriteLog(
            dt,
            TextBox2.Text,
            TextBox3.Text,
            TextBox4.Text,
            TextBox5.Text);

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        List<WebService.KMessage> outList;
        DataBaseAccess dba = GetDataBaseAccess();
        DateTime lastUpdate = DateTime.Now.Subtract(new TimeSpan(0,0,0,int.Parse(TextBox6.Text),0));
        string group = TextBox7.Text;
        dba.ReadLog(lastUpdate, group, out outList);

        WebService.KMessage[] outM = outList.ToArray();
        outList.Clear();
        outList = null;

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        foreach (WebService.KMessage km in outM)
        {
            sb.Append(km.Time);
            sb.Append(km.Group);
            sb.Append(km.SenderName);
            sb.Append(km.DestName);
            sb.Append(km.Log);
            sb.Append(" ");
        }
        TextBox8.Text = sb.ToString();
    }
}
